<?php

class DispatchAction extends CAction
{
    public function run()
    {
	$text=Html::encode($_POST['ShellForm']['comand']); 
	if(strlen($text)==strlen(preg_replace('/\s+/','',$text))){
		$command = $text;
	}else{
		$command = substr($text, 0, strpos($text, ' '));
		$data = substr(strstr($text, ' '), 1);
	}
	

        echo '<b>admin@eduow:~$&nbsp;</b>'.$command.' '.$data.'<br/>';
	
	$baseClass = 'Command';
	$targetClass = ucfirst($command).$baseClass;

	if(is_file(dirname(__FILE__).'/'.$targetClass.'.php')){
		include_once($targetClass.'.php');
		if (class_exists($targetClass) && is_subclass_of($targetClass, $baseClass)){
	    		$runner = new $targetClass;
            		$runner->run($data);
			echo '<br/>';
        	}
	}else{
            	echo "<span class=\"shellerror\">Командата <b>$command</b> не е намерена.</span><br/>Напишете help за списък на всички команди.<br/>";
	}
	
	
    }
}

?>
